<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <!--关于VueComponent的5个注意点-->
    <div id="root">
        <school></school> <!--2.页面渲染到组件标签时，Vue会自动调用new VueComponent(options)创建VueComponent实例，简称vc实例-->
        <student></student>
    </div>

    <script>
        Vue.config.productionTip = false

        //school组件
        let sch = Vue.extend({ 
            name: 'school',
            template: `
                <div>
                    <h2>学校名称：{{name}}</h2>
                    <h2>学校地址：{{address}}</h2>
                    <button @click='showName'>点我提示学校名</button>
                </div>
            `,
            data() {
              return {
                name: 'shanggg',
                address: 'bj',
              }
            },
            methods: {
                showName() {
                    //4.组件data、methods、watch、computed等属性的函数中，this指向都是VueComponent实例对象，不是Vue实例对象
                    console.log(this) //VueComponent {xxxx}

                    //5.VueComponent实例相当于一个微型的Vue实例，也有数据代理，数据监视等功能
                    alert(this.name)
                }
            }
        })
        //student组件
        let stu = Vue.extend({ 
            name: 'student',
            template: `
                <div>
                    <h2>名称：{{name}}</h2>
                    <h2>年龄{{age}}</h2>
                </div>
            `,
            data() {
              return {
                name: 'zs',
                age: 19,
              }
            }
        })
        
        let vm = new Vue({
            el: "#root",
            components: {
                school: sch,
                student: stu,
            }
        })

        //1.组件的本质就是VueComponent构造函数，通过Vue.extend生成
        console.log(sch) //function VueComponent() {...}
        console.log(stu)
        //3.不同组件虽然都叫VueComponent构造函数，每次调用Vue.extend都生成全新的VueComponent构造函数
        console.log(sch === stu) //false

        //一个vm管理着多个vc，都挂在vm.$children下;同理一个vc也可以管理多个vc，都挂在vc.$children下
        console.log(vm.$children)
        //console.log(vm.$children[0].$children)
    </script>
</body>
</html>